/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

package com.nanosl.norg.ent;

import java.io.Serializable;
import java.util.Collection;
import java.util.Date;
import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.EmbeddedId;
import javax.persistence.Entity;
import javax.persistence.JoinColumn;
import javax.persistence.JoinTable;
import javax.persistence.ManyToMany;
import javax.persistence.ManyToOne;
import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery;
import javax.persistence.OneToMany;
import javax.persistence.Table;
import javax.persistence.Temporal;
import javax.persistence.TemporalType;
import javax.xml.bind.annotation.XmlRootElement;
import javax.xml.bind.annotation.XmlTransient;

/**
 *
 * @author Thilina
 */
@Entity
@Table(name = "employee")
@XmlRootElement
@NamedQueries({
    @NamedQuery(name = "Employee.findAll", query = "SELECT e FROM Employee e"),
    @NamedQuery(name = "Employee.findById", query = "SELECT e FROM Employee e WHERE e.employeePK.id = :id"),
    @NamedQuery(name = "Employee.findByOrganizationId", query = "SELECT e FROM Employee e WHERE e.employeePK.organizationId = :organizationId"),
    @NamedQuery(name = "Employee.findByAppointment", query = "SELECT e FROM Employee e WHERE e.appointment = :appointment"),
    @NamedQuery(name = "Employee.findByResign", query = "SELECT e FROM Employee e WHERE e.resign = :resign")})
public class Employee implements Serializable {
    private static final long serialVersionUID = 1L;
    @EmbeddedId
    protected EmployeePK employeePK;
    @Column(name = "appointment")
    @Temporal(TemporalType.DATE)
    private Date appointment;
    @Column(name = "resign")
    @Temporal(TemporalType.DATE)
    private Date resign;
    @JoinTable(name = "employee_has_deduction", joinColumns = {
        @JoinColumn(name = "employee_id", referencedColumnName = "id"),
        @JoinColumn(name = "employee_organization_id", referencedColumnName = "organization_id")}, inverseJoinColumns = {
        @JoinColumn(name = "deduction_id", referencedColumnName = "id")})
    @ManyToMany
    private Collection<Deduction> deductionCollection;
    @JoinTable(name = "employee_has_addition", joinColumns = {
        @JoinColumn(name = "employee_id", referencedColumnName = "id"),
        @JoinColumn(name = "employee_organization_id", referencedColumnName = "organization_id")}, inverseJoinColumns = {
        @JoinColumn(name = "addition_id", referencedColumnName = "id")})
    @ManyToMany
    private Collection<Addition> additionCollection;
    @OneToMany(cascade = CascadeType.ALL, mappedBy = "employee")
    private Collection<Attendance> attendanceCollection;
    @JoinColumn(name = "designation_id", referencedColumnName = "id")
    @ManyToOne(optional = false)
    private Designation designation;
    @JoinColumn(name = "department_id", referencedColumnName = "id")
    @ManyToOne(optional = false)
    private Department department;
    @JoinColumn(name = "person_NIC", referencedColumnName = "NIC")
    @ManyToOne(optional = false)
    private Person person;
    @JoinColumn(name = "organization_id", referencedColumnName = "id", insertable = false, updatable = false)
    @ManyToOne(optional = false)
    private Organization organization;

    public Employee() {
    }

    public Employee(EmployeePK employeePK) {
        this.employeePK = employeePK;
    }

    public Employee(String id, String organizationId) {
        this.employeePK = new EmployeePK(id, organizationId);
    }

    public EmployeePK getEmployeePK() {
        return employeePK;
    }

    public void setEmployeePK(EmployeePK employeePK) {
        this.employeePK = employeePK;
    }

    public Date getAppointment() {
        return appointment;
    }

    public void setAppointment(Date appointment) {
        this.appointment = appointment;
    }

    public Date getResign() {
        return resign;
    }

    public void setResign(Date resign) {
        this.resign = resign;
    }

    @XmlTransient
    public Collection<Deduction> getDeductionCollection() {
        return deductionCollection;
    }

    public void setDeductionCollection(Collection<Deduction> deductionCollection) {
        this.deductionCollection = deductionCollection;
    }

    @XmlTransient
    public Collection<Addition> getAdditionCollection() {
        return additionCollection;
    }

    public void setAdditionCollection(Collection<Addition> additionCollection) {
        this.additionCollection = additionCollection;
    }

    @XmlTransient
    public Collection<Attendance> getAttendanceCollection() {
        return attendanceCollection;
    }

    public void setAttendanceCollection(Collection<Attendance> attendanceCollection) {
        this.attendanceCollection = attendanceCollection;
    }

    public Designation getDesignation() {
        return designation;
    }

    public void setDesignation(Designation designation) {
        this.designation = designation;
    }

    public Department getDepartment() {
        return department;
    }

    public void setDepartment(Department department) {
        this.department = department;
    }

    public Person getPerson() {
        return person;
    }

    public void setPerson(Person person) {
        this.person = person;
    }

    public Organization getOrganization() {
        return organization;
    }

    public void setOrganization(Organization organization) {
        this.organization = organization;
    }

    @Override
    public int hashCode() {
        int hash = 0;
        hash += (employeePK != null ? employeePK.hashCode() : 0);
        return hash;
    }

    @Override
    public boolean equals(Object object) {
        // TODO: Warning - this method won't work in the case the id fields are not set
        if (!(object instanceof Employee)) {
            return false;
        }
        Employee other = (Employee) object;
        if ((this.employeePK == null && other.employeePK != null) || (this.employeePK != null && !this.employeePK.equals(other.employeePK))) {
            return false;
        }
        return true;
    }

    @Override
    public String toString() {
        return "com.nanosl.norg.ent.Employee[ employeePK=" + employeePK + " ]";
    }
    
}
